package com.szty.lib_pen.sendPoint.longConnect.client;

import android.util.Log;

import com.szty.lib_pen.sendPoint.longConnect.manager.ClientConnectManager;
import com.szty.lib_pen.sendPoint.longConnect.manager.SessionManager;

import org.apache.mina.core.service.IoService;
import org.apache.mina.core.service.IoServiceListener;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;


/**
 * Created by huanghongfa on 2017/7/28.
 * 监听服务器断线原因
 */

public class HeartBeatListener implements IoServiceListener {
    private String TAG = getClass().getSimpleName();

    public HeartBeatListener( ) {

    }

    @Override
    public void serviceActivated(IoService arg0) {
        Log.i(TAG,"连接成功");
    }

    @Override
    public void serviceDeactivated(IoService arg0) {
    }

    @Override
    public void serviceIdle(IoService arg0, IdleStatus arg1) {

    }

    @Override
    public void sessionClosed(IoSession arg0) {
        SessionManager.getInstance().closeSession();
        SessionManager.getInstance().removeSession();
    }

    @Override
    public void sessionCreated(IoSession arg0) {
    }

    @Override
    public void sessionDestroyed(IoSession arg0) {
        Log.i(TAG,"连接断开");
        SessionManager.getInstance().closeSession();
        SessionManager.getInstance().removeSession();
        if(ClientConnectManager.getInstance().isRePeatConnect){
            ClientConnectManager.getInstance().rePeatConnect();
        }
    }

}
